'use strict';
function numToChar(num){
  let remainder=num%26;
  let quotient=parseInt(num/26);
  if(quotient==0){
     return String.fromCharCode(remainder+96);
  }
  else if(quotient==1 && remainder==0){
    return 'z';
  }
  else if(quotient>1&&remainder==0){
    return numToChar(quotient-1)+'z';
  }
  else{
    return numToChar(quotient) + String.fromCharCode(remainder + 96);
  }
}

function median_to_letter(collection) {
  var i=collection.length/2;
  var answer,result;
  
  if(collection.length%2==0){
     answer=(collection[i]+collection[i-1])/2;
     var a=(collection[i]+collection[i-1])%2
     if(a==0){
        result=numToChar(answer);
     }else{
        result=numToChar(parseInt(answer)+1); 
     }
  }else{
        answer=ab[ parseInt(collection.length/2)];
        result=numToChar(answer);
  }
  console.log(answer);
  console.log(result);
  return result;  //在这里写入代码
}

module.exports = median_to_letter;
